﻿using MemoryPack;

namespace Basic.Base.Serialization;

public class DefaultMemoryPackSerializer : ISerializer
{
    public string Name => SerializerConst.MemoryPack;

    public T Deserialize<T>(byte[] bytes)
    {
        return bytes == null ? default(T) : MemoryPackSerializer.Deserialize<T>(bytes);
    }

    public object Deserialize(byte[] bytes, Type type)
    {
        return bytes == null ? null : MemoryPackSerializer.Deserialize(type, bytes);
    }

    public byte[] Serialize<T>(T value)
    {
        return value == null ? null : MemoryPackSerializer.Serialize(value);
    }

    public byte[] SerializeObject(object obj)
    {
        return obj == null ? null : MemoryPackSerializer.Serialize(obj.GetType(), obj);
    }
}
